package com.cat.dynamicPlanning02;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/sort-integers-by-the-power-value/?envType=problem-list-v2&envId=dynamic-programminghttps://leetcode.cn/problems/sort-integers-by-the-power-value/?envType=problem-list-v2&envId=dynamic-programming
 * @create 2025/11/6 14:52
 * @since JDK17
 */

public class Solution46 {
    int weight(int num) {
        int ans = 0;
        while (num != 1) {
            if (num % 2 != 1) {
                num /= 2;
            } else {
                num = num * 3 + 1;
            }
            ans++;
        }
        return ans;
    }
    public int getKth(int lo, int hi, int k) {
        int[][] arr = new int[hi - lo + 1][2];
        for (int i = 0; i <= hi - lo; i++) {
            arr[i][0] = i + lo;
            arr[i][1] = weight(i + lo);
        }
        Arrays.sort(arr, (a, b) -> a[1] - b[1]);
        return arr[k - 1][0];
    }
}
